/**
 * 
 */
package com.itinsys.enma.service.impl;

import java.sql.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.itinsys.enma.domain.Period;
import com.itinsys.enma.manager.PeriodManager;
import com.itinsys.enma.service.PeriodDateChecker;

/**
 * @author pferraz
 *
 */
public class PeriodDateCheckerImpl implements PeriodDateChecker{

	private static Logger logger = Logger.getLogger("service");
	
	@Autowired
	private PeriodManager periodManager;

	@Override
	public void checkPeriodDates() {
		logger.info("Inicia chequeo de periodos");
		
		List<Period> periodsToEnd=periodManager.getPeriodsToEnd(new Date(new java.util.Date().getTime()).toString());
		for(Period period:periodsToEnd){
			period.setActive(false);
			periodManager.directUpdate(period);
				
		}
	
		
		logger.info("Finaliza chequeo de periodos");
		
	}
	
	
}
